﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Itfort;
using MySoft.Data;


namespace Users
{
	public class SsoService : ISsoService
	{
		private DbSession dbSession = new DbSession("Users");

		public AuthTicket CreateAuthTicket(Guid token, string identity, DateTime expires)
		{
			_AuthTicket _ticket = new _AuthTicket();
			_ticket.Token = token;
			_ticket.Identity = identity;
			_ticket.Expires = expires;
			_ticket.CreationTime = DateTime.Now;

			dbSession.Save(_ticket);
			return _ticket.Convert2<AuthTicket>();
		}

		public AuthTicket GetAuthTicket(Guid token)
		{
			return dbSession.Single<_AuthTicket>(_AuthTicket._.Token == token)
				.Convert2<AuthTicket>();
		}
	}
}
